package com.cuitrip.business.reminder.model;

import android.view.View;

import com.cuitrip.apiservice.OrderBusiness;
import com.cuitrip.business.order.model.OrderItem;
import com.cuitrip.business.pay.PayOrderPageActivity;
import com.cuitrip.business.tripservice.model.ServiceInfo;
import com.cuitrip.push.model.PushMessageModel;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.cuitrip.util.time.InputTime;
import com.cuitrip.util.time.OutputTime;
import com.cuitrip.util.time.TimeUtil;
import com.lab.network.config.CtResponseCode;
import com.lab.network.model.CtApiResponse;
import com.lab.network.model.IProxyCallback;
import com.lab.network.model.ProxyResult;
import com.lab.network.proxy.ApiProxy;
import com.lab.rtenvironment.AppCoreRuntime;

/**
 * Created by ak on 15/11/5.
 */
public class ConfirmSuccessViewHolder extends ReminderInfoViewHolder {


    private ServiceInfo serviceInfo;

    @Override
    public void render(final PushMessageModel object) {
        serviceName.setText(object.getServiceName());
        title.setText(ResourceUtil.getString(R.string.book_popup_suc));
        if (object.getPersonCount() > 1){
            try {
                subTitle.setText(ResourceUtil.getString(R.string.book_popup_suc_desc_2, Integer.valueOf(object.getPersonCount())));
            }catch (NumberFormatException e){

            }
        }else{
            subTitle.setText(ResourceUtil.getString(R.string.book_popup_suc_desc_1));
        }
        String timeFormat = TimeUtil.formatTime(
                InputTime.build(object.getServiceDate(), TimeUtil.getZeroZone()),
                OutputTime.getInstance(OutputTime.OutputType.Type_DAY, TimeUtil.getZeroZone()));
        dateText.setText(timeFormat);
        long l = TimeUtil.parseString2Long(object.getServiceDate(), "yyyy-MM-dd");

        dateText.setText(TimeUtil.formatDay(AppCoreRuntime.context,l));
        actionStatus.setText(ResourceUtil.getString(R.string.correct_icon));
        firstAction.setText(ResourceUtil.getString(R.string.pay_operation_pay_now));
        secondAction.setVisibility(View.GONE);
        firstAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mWeakHostActivity.get().isNeedChangeType()) {
                    changeType("cuitrip://pay?oid=" + object.getMessageId());
                } else {

                    OrderBusiness.getOrderInfo(new ApiProxy(new IProxyCallback() {
                        @Override
                        public boolean onProxyResult(ProxyResult<?> result) {
                            CtApiResponse response = (CtApiResponse) result.getData();
                            if (response != null && response.code == CtResponseCode.RESULT_OK) {
                                if ((response.result instanceof OrderItem)){
                                    OrderItem orderItem= (OrderItem) response.result;
//                                    PayOrderPageActivity.startActivity(mWeakHostActivity.get(),orderItem);
                                    PayOrderPageActivity.startActivity(mWeakHostActivity.get(),orderItem.getOid());
                                }
                            }
                            return false;
                        }
                    }),object.getMessageId());
                    }
                }
        });
    }


}
